#include<iostream>
#include<stdlib.h>
#include<stdio.h>

using namespace std;

int arr[200] = { 0 };

typedef struct TreeNode
{
	int val;
	TreeNode* left;
	TreeNode* right;
}TN;

int judge(TN* &root, int val, TN* &newnode)
{
	if (val > root->val && root->right==NULL)
	{
		root->right = newnode;
		return 0;
	}
	else if (val < root->val && root->left == NULL)
	{
		root->left = newnode;
		return 0;
	}
	if (val == root->val)
	{
		return 0;
	}
	if (val > root->val)
	{
		judge(root->right, val, newnode);
	}
	else if (val < root->val)
	{
		judge(root->left, val, newnode);
	}
	return 0;
}

int InOrder(TN* root)
{
	if (root == NULL)
	{
		return 0;
	}
	InOrder(root->left);
	cout << root->val << " ";
	InOrder(root->right);
	return 0;
}

int main()
{
	TN* root = (TN*)malloc(sizeof(TN));
	root->left = nullptr;
	root->right = nullptr;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	root->val = arr[0];
	for (int i = 1; i < n; i++)
	{
		TN* newnode = (TN*)malloc(sizeof(TN));
		newnode->val = arr[i];
		newnode->left = nullptr;
		newnode->right = nullptr;
		judge(root, arr[i], newnode);
	}

	InOrder(root);
	cout << endl;
}
